## This test checks debug info for the case when one compilation unit
## contains a forward declaration of a type and another compilation unit
## contains a definition for that type. The result should contain
## the original definition and the declaration without modifications.

# RUN: yaml2obj %s -o %t.o
# RUN: llvm-dwarfutil %t.o - | llvm-dwarfdump -a - | FileCheck %s

## CU1:
##
## class class1;
## template<int> class class2;
##
## class1 *var1;
## class2<int> *var2;
##
## CU2:
##
## class class1 {
##   char member1;
##   float member2;
## };
##
## template<int> class class2 {
##   char member1;
## };
##
## class1 *var1;
## class2<int> *var2;

# CHECK: file format elf64-x86-64
# CHECK: .debug_info contents:

# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_name{{.*}}"CU1"

# CHECK: 0x[[CU1_CLASS1:[0-9a-f]*]]: DW_TAG_class_type{{.*[[:space:]].*}}DW_AT_name{{.*}}"class1"
# CHECK: DW_AT_declaration (true)

# CHECK: 0x[[CU1_CLASS2:[0-9a-f]*]]: DW_TAG_class_type{{.*[[:space:]].*}}DW_AT_name{{.*}}"class2"
# CHECK: DW_AT_declaration (true)
# CHECK: DW_TAG_template_type_parameter{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU1_INT:[0-9a-f]*]] "int"

# CHECK: 0x[[CU1_INT]]: DW_TAG_base_type
# CHECK: DW_AT_name{{.*}}"int"

# CHECK: 0x[[CU1_PTR_CLASS1:[0-9a-f]*]]: DW_TAG_pointer_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU1_CLASS1]] "class1"

# CHECK: 0x[[CU1_PTR_CLASS2:[0-9a-f]*]]: DW_TAG_pointer_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU1_CLASS2]] "class2<int>"

# CHECK: DW_TAG_variable
# CHECK: DW_AT_name{{.*}}"var1"
# CHECK: DW_AT_type{{.*}}0x00000000[[CU1_PTR_CLASS1]] "class1 *"
# CHECK: DW_TAG_variable
# CHECK: DW_AT_name{{.*}}"var2"
# CHECK: DW_AT_type{{.*}}0x00000000[[CU1_PTR_CLASS2]] "class2<int> *"

# CHECK: DW_TAG_compile_unit
# CHECK: DW_AT_name{{.*}}"CU2"

# CHECK: 0x[[CU2_CLASS1:[0-9a-f]*]]: DW_TAG_class_type{{.*[[:space:]].*}}DW_AT_name{{.*}}"class1"
# CHECK: DW_TAG_member
# CHECK: DW_AT_type{{.*}}0x00000000[[CU2_CHAR:[0-9a-f]*]] "char"
# CHECK: DW_AT_name{{.*}}"member1"

# CHECK: DW_TAG_member
# CHECK: DW_AT_type{{.*}}0x00000000[[CU2_FLOAT:[0-9a-f]*]] "float"
# CHECK: DW_AT_name{{.*}}"member2"

# CHECK: 0x[[CU2_CLASS2:[0-9a-f]*]]: DW_TAG_class_type{{.*[[:space:]].*}}DW_AT_name{{.*}}"class2"
# CHECK: DW_TAG_template_type_parameter{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU2_INT:[0-9a-f]*]] "int"
# CHECK: DW_TAG_member
# CHECK: DW_AT_type{{.*}}0x00000000[[CU2_CHAR]] "char"
# CHECK: DW_AT_name{{.*}}"member1"

# CHECK: 0x[[CU2_INT]]: DW_TAG_base_type
# CHECK: DW_AT_name{{.*}}"int"

# CHECK: 0x[[CU2_CHAR]]: DW_TAG_base_type
# CHECK: DW_AT_name{{.*}}"char"

# CHECK: 0x[[CU2_FLOAT]]: DW_TAG_base_type
# CHECK: DW_AT_name{{.*}}"float"

# CHECK: 0x[[CU2_PTR_CLASS1:[0-9a-f]*]]: DW_TAG_pointer_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU2_CLASS1]] "class1"

# CHECK: 0x[[CU2_PTR_CLASS2:[0-9a-f]*]]: DW_TAG_pointer_type{{.*[[:space:]].*}}DW_AT_type{{.*}}0x00000000[[CU2_CLASS2]] "class2<int>"

# CHECK: DW_TAG_variable
# CHECK: DW_AT_name{{.*}}"var1"
# CHECK: DW_AT_type{{.*}}0x00000000[[CU2_PTR_CLASS1]] "class1 *"
# CHECK: DW_TAG_variable
# CHECK: DW_AT_name{{.*}}"var2"
# CHECK: DW_AT_type{{.*}}0x00000000[[CU2_PTR_CLASS2]] "class2<int> *"

--- !ELF
FileHeader:
  Class:    ELFCLASS64
  Data:     ELFDATA2LSB
  Type:     ET_REL
  Machine:  EM_X86_64
Sections:
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    Address:         0x1000
    Size:            0x1b
  - Name:            .text2
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    Address:         0x2000
    Size:            0x1b
DWARF:
  debug_abbrev:
    - Table:
      - Tag:      DW_TAG_compile_unit
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_producer
            Form:      DW_FORM_string
          - Attribute: DW_AT_language
            Form:      DW_FORM_data2
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addr
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_member
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_declaration
            Form:      DW_FORM_flag_present
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_declaration
            Form:      DW_FORM_flag_present
      - Tag:      DW_TAG_template_type_parameter
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
      - Tag:      DW_TAG_base_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_pointer_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
      - Tag:      DW_TAG_variable
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_const_value
            Form:      DW_FORM_data4
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
    - Table:
      - Tag:      DW_TAG_compile_unit
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_producer
            Form:      DW_FORM_string
          - Attribute: DW_AT_language
            Form:      DW_FORM_data2
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addr
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_member
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_declaration
            Form:      DW_FORM_flag_present
      - Tag:      DW_TAG_class_type
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_declaration
            Form:      DW_FORM_flag_present
      - Tag:      DW_TAG_template_type_parameter
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
      - Tag:      DW_TAG_base_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
      - Tag:      DW_TAG_pointer_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
      - Tag:      DW_TAG_variable
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_const_value
            Form:      DW_FORM_data4
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref_addr
  debug_info:
    - Version: 4
      Entries:
        - AbbrCode: 1
          Values:
            - CStr: by_hand
            - Value:  0x04
            - CStr: CU1
            - Value:  0x1000
            - Value:  0x1b
        - AbbrCode: 4
          Values:
            - CStr: class1
        - AbbrCode: 5
          Values:
            - CStr: class2
        - AbbrCode: 6
          Values:
            - Value:  0x00000040
        - AbbrCode: 0
        - AbbrCode: 7
          Values:
            - CStr: int
        - AbbrCode: 8
          Values:
            - Value:  0x0000002a
        - AbbrCode: 8
          Values:
            - Value:  0x00000032
        - AbbrCode: 9
          Values:
            - CStr: var1
            - Value:  0x00000000
            - Value:  0x00000045
        - AbbrCode: 9
          Values:
            - CStr: var2
            - Value:  0x00000000
            - Value:  0x0000004a
        - AbbrCode: 0
    - Version: 4
      Entries:
        - AbbrCode: 1
          Values:
            - CStr: by_hand
            - Value:  0x04
            - CStr: CU2
            - Value:  0x2000
            - Value:  0x1b
        - AbbrCode: 2
          Values:
            - CStr: class1
        - AbbrCode: 3
          Values:
            - Value:  0x000000d9
            - CStr: member1
        - AbbrCode: 3
          Values:
            - Value:  0x000000df
            - CStr: member2
        - AbbrCode: 0
        - AbbrCode: 2
          Values:
            - CStr: class2
        - AbbrCode: 6
          Values:
            - Value:  0x000000d4
        - AbbrCode: 3
          Values:
            - Value:  0x000000d9
            - CStr: member1
        - AbbrCode: 0
        - AbbrCode: 7
          Values:
            - CStr: int
        - AbbrCode: 7
          Values:
            - CStr: char
        - AbbrCode: 7
          Values:
            - CStr: float
        - AbbrCode: 8
          Values:
            - Value:  0x00000096
        - AbbrCode: 8
          Values:
            - Value:  0x000000b9
        - AbbrCode: 9
          Values:
            - CStr: var1
            - Value:  0x00000000
            - Value:  0x000000e6
        - AbbrCode: 9
          Values:
            - CStr: var2
            - Value:  0x00000000
            - Value:  0x000000eb
        - AbbrCode: 0
...
